package controllers

import (
	"github.com/astaxie/beego"
)

type TestLoginController struct {
	beego.Controller
}

type UserInfo struct {
	Username string
	Password string

}

func (c *TestLoginController) Login() {
	name := c.Ctx.GetCookie("name");
	password := c.Ctx.GetCookie("password");

	if name != ""{
		c.Ctx.WriteString("Username:" + name + "passwork:" + password)
	}else{
		c.Ctx.WriteString(`<html><form action="/test_login" method="post"> 
				<input type="text" name="Username" />
				<input type="password" name="Password" />
				<input type="submit" value="提交" />
			</form> </html>`)
	}
}


func (c *TestLoginController) Post() {
	u := UserInfo{}
	if err := c.ParseForm(&u) ; err != nil{

	}

	c.Ctx.SetCookie("name", u.Username, 100, "/")
	c.Ctx.SetCookie("password", u.Password, 100, "/")

	c.Ctx.WriteString("Username:" + u.Username + u.Password)
	//id := this.Input().Get("id")
	//intid, err := strconv.Atoi(id)
}

